import service from "@/axios/index";
import {useCounterStore} from '@/stores/counter'

const counterStore = useCounterStore()
//登录
export function loginPost(data: object) {
    return service.post("/yucheng/login", data, {
        headers: {
            "Content-Type": "application/json"
        }
    })
}

// export function GetUserIP(){
//     //获取IP
//     axios.get('https://api.ipify.org?format=json')
//         .then(response => {
//             counterStore.userIP = response.data.ip;
//         })
//         .catch(error => {
//             console.log(error);
//         });
// }

/*---------------------------------------------------*/
//获取分类
export function getCategoryAPI(data: object) {
    return service.get("/yucheng/category/getCategoryList", {
        params: data,
        headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            // "token": counterStore.token,
            // Authorization:`Bearer ${counterStore.token}`
            Authorization:counterStore.token
        }
    })
}
//分类编辑
export function updateCategoryAPI(data: object) {
    return service.put("/yucheng/category/updateCategory", data, {
        headers: {
            "Content-type": "application/json",
            // Authorization:counterStore.token,
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除分类
export function deleteCategoryAPI(data: object) {
    return service.delete("/yucheng/category/deleteCategory", {
        params: data,
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加分类
export function addCategoryAPI(data: object) {
    return service.put("/yucheng/category/addCategory", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*---------------------------------------------------*/
//获取商品
export function getGoodsAPI(data: object) {
    getIsWarnListAPI()
    return service.get("/yucheng/stock/getStockList", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//修改商品
export function updateGoodsAPI(data: object) {
    getIsWarnListAPI()
    return service.put("/yucheng/stock/updateStock", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除商品
export function deleteGoodsAPI(data: object) {
    getIsWarnListAPI()
    return service.delete("/yucheng/stock/deleteStock", {
        data: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加商品
export function addGoodsAPI(data: object) {
    getIsWarnListAPI()
    return service.post("/yucheng/stock/addStock", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*---------------------------------------------------*/
//获取商品入库记录
export function getGoodsInAPI(data: object) {
    getIsWarnListAPI()
    return service.get("/yucheng/storage/getStorageList", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//修改入库记录
export function updateGoodsInAPI(data: object) {
    getIsWarnListAPI()
    return service.put("/yucheng/storage/updateStorage", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除入库记录
export function deleteGoodsInAPI(data: object) {
    getIsWarnListAPI()
    return service.delete("/yucheng/storage/deleteStorage", {
        params: data,
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加商品入库
export function addGoodsInAPI(data: object) {
    getIsWarnListAPI()
    return service.post("/yucheng/storage/addStorage", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}

/*---------------------------------------------------*/
//获取商品数量预警记录
export function getGoodsWarningAPI(data: object) {
    getIsWarnListAPI()
    return service.get("/yucheng/warn/getWarnList", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//商品数量预警记录修改
export function updateGoodsWarningAPI(data: object) {
    getIsWarnListAPI()
    return service.put("/yucheng/warn/updateWarn", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//商品数量预警记录删除
export function deleteGoodsWarningAPI(data: object) {
    getIsWarnListAPI()
    return service.delete("/yucheng/warn/deleteWarn", {
        data: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//获取预警消息
export function getIsWarnListAPI() {
    return service.get("/yucheng/warn/getIsWarnList", {
        headers: {
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加商品数量预警
export function addGoodsWarningAPI(data: object) {
    getIsWarnListAPI()
    return service.put("/yucheng/warn/addWarn", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*----------------------------------------------------------------*/
//获取销售记录
export function getSalesRecordAPI(data: object) {
    getIsWarnListAPI()
    return service.get("/yucheng/outbound/getOutboundGoodList", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//获取出库订单详情列表
export function getOrderDetailAPI(data: object) {
    getIsWarnListAPI()
    return service.get("/yucheng/outbound/getOutboundGoodDetailList", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//编辑销售记录
export function updateSalesRecordAPI(data:object){
    getIsWarnListAPI()
    return service.put("/yucheng/outbound/updateOutboundDetail", data, {
        // params:{
        //     gid:null
        // },
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除销售记录
export function deleteSalesRecordAPI(data: object) {
    getIsWarnListAPI()
    return service.delete("/yucheng/outbound/deleteOutbound", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加销售单
export function addSalesAPI(data: object,List) {
    getIsWarnListAPI()
    return service.post("/yucheng/outbound/addOutbound", List, {
        params:data,
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*--------------------------------------------------------------------*/
//获取损耗单
export function getLossRecordAPI() {
    getIsWarnListAPI()
    return service.get("/yucheng/outbound/getLossList", {
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加损耗单
export function addLossAPI(data: object) {
    getIsWarnListAPI()
    return service.put("/yucheng/outbound/addLoss", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*------------------------------*/
//获取收货单位
export function getConsigneeAPI(data:object){
    getIsWarnListAPI()
    return service.get("/yucheng/receiving/getReceivingList",{
        params:data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//编辑收货单位
export function updateConsigneeAPI(data:object){
    getIsWarnListAPI()
    return service.put("/yucheng/receiving/updateReceiving",data,{
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除收货单位
export function deleteConsigneeAPI(data:object){
    getIsWarnListAPI()
    return service.delete("/yucheng/receiving/deleteReceiving", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加收货单位
export function addConsigneeAPI(data:object){
    getIsWarnListAPI()
    return service.post("/yucheng/receiving/addReceiving", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
/*------------------------------------*/
//查询表格单价
export function lookUnivalenceAPI(data:object){
    return service.get("/yucheng/receiving/getReceivingCostPriceList",{
        params:data,
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//编辑表格单价
export function updateUnivalenceAPI(data:object){
    return service.put("/yucheng/receiving/updateReceivingCostPrice",data,{
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//删除表格单价
export function deleteUnivalenceAPI(data:object){
    return service.delete("/yucheng/receiving/deleteReceivingCostPrice", {
        params: data,
        headers: {
            "Content-type": "application/x-www-form-urlencoded",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//添加表格单价
export function addUnivalenceAPI(data:object){
    return service.post("/yucheng/receiving/addReceivingGoodPrice", data, {
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}
//获取筛选单价
export function getUnivalenceAPI(data:object){
    return service.get("/yucheng/receiving/getReceivingCostPrice", {
        params:data,
        headers: {
            "Content-type": "application/json",
            Authorization:`Bearer ${counterStore.token}`
        }
    })
}